package com.tony.mindhr.controller.system.basic;

import com.tony.mindhr.model.Position;
import com.tony.mindhr.model.RespBean;
import com.tony.mindhr.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: PositionController
 * @Auther: 皮蛋布丁
 * @Date: 2021/05/19/21:58
 * @Description: 基础信息设置
 */
@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {
    @Autowired
    PositionService positionService;

    @GetMapping("/")
    public List<Position> getAllPositions () {
        return positionService.getAllPositions();
    }

    /**
    * @Description: addPosition 新增
    * @Param: [position]
    * @return: com.tony.mindhr.model.RespBean
    * @Author: 皮蛋布丁
    * @Date: 2021/5/19 22:22
    */
    //@RequestBody :json形式传递
    @PostMapping("/")
    public RespBean addPosition(@RequestBody Position position) {
        if (positionService.addPosition(position) == 1) {
            return RespBean.ok("添加成功！");
        }
        return RespBean.error("添加失败！");
    }

    /**
    * @Description: updatePositions 更新
    * @Param: [position]
    * @return: com.tony.mindhr.model.RespBean
    * @Author: 皮蛋布丁
    * @Date: 2021/5/19 22:27
    */
    @PutMapping("/")
    public RespBean updatePositions(@RequestBody Position position) {
        if (positionService.updatePositions(position) == 1) {
            return RespBean.ok("更新成功！");
        }
        return RespBean.error("更新失败！");
    }


    @DeleteMapping("/{id}")
    public RespBean deletePositionById(@PathVariable Integer id) {
        if (positionService.deletePositionById(id) == 1) {
            return RespBean.ok("删除成功！");
        }
        return RespBean.ok("删除失败！");
    }

    @DeleteMapping("/")
    public RespBean deletePositionByIds(Integer[] ids) {
        if(positionService.deletePositionByIds(ids) == ids.length) {
            return RespBean.ok("删除成功！");
        }
        return RespBean.error("删除失败！");
    }



}
